import Mock from 'mockjs'
import { doCustomTimes } from '../utils/tools'
import type { Note } from '@/stores/types/index'
const Random = Mock.Random

export const mockNoteList = () => {
  const data: Note[] = []
  doCustomTimes(2, (index) => {
    data.push({
      dates: Random.date('yyyy-MM-dd'),
      content: 'ccc', //Random.csentence(1, 50),
      _id: Random.string('lower', 12)
    })
  })
  return {
    code: 200,
    message: '操作成功',
    data
  }
}

export const mockNoteById = () => {
  return {
    code: 200,
    message: '操作成功',
    data: {
      dates: Random.date('yyyy-MM-dd'),
      content: Random.csentence(1, 50),
      _id: Random.string(12)
    }
  }
}
export const mockOK = () => {
  return {
    code: 200,
    message: '操作成功',
    data: null
  }
}

// Mock.mock(/\/note\/page/, mockNoteList)
// Mock.mock(/\/note\/id/, mockNoteById)

// Mock.mock(/\/note\/content/, mockNoteList)
// Mock.mock(/\/note/, 'post', mockNoteById)
// Mock.mock(/\/note/, 'delete', mockOK)
// Mock.mock(/\/note/, 'put', mockNoteById)

import { type MockMethod } from 'vite-plugin-mock'
export default [
  // {
  //   url: /\/note\/page\/\d+\/\d+/,
  //   method: 'get',
  //   response: ({ query }) => {
  //     return mockNoteList()
  //   }
  // },
  {
    url: /\/note\/id\//,
    method: 'get',
    response: ({ query }) => {
      return mockNoteById()
    }
  },
  {
    url: /\/note\/content\//,
    method: 'get',
    response: ({ query }) => {
      return mockNoteList()
    }
  },
  // {
  //   url: /\/note/,
  //   method: 'post',
  //   response: ({ query }) => {
  //     return mockNoteById()
  //   }
  // },
  {
    url: /\/note/,
    method: 'delete',
    response: ({ query }) => {
      return mockOK()
    }
  },
  {
    url: /\/note/,
    method: 'put',
    response: ({ query }) => {
      return mockNoteById()
    }
  }
] as MockMethod[]
